using UnityEngine;

//灯光闪烁
[RequireComponent(typeof(Light))]
public class LightFlicker : MonoBehaviour {
    private new Light light;
    public float min = 1.2f; //最小亮度
    public float max = 2.0f; //最大亮度

    private void Awake() {
        light = GetComponent<Light>(); //获取灯光组件
    }

    private void Update() {
        float noise = Mathf.PerlinNoise(Time.time, Time.time *5.0f); //使用Perlin噪声生成随机数
        light.intensity = Mathf.Lerp(min, max, noise); //根据随机数设置灯光亮度
    }
}
